#include<bits/stdc++.h>
#define ll long long
using namespace std;
int rd()
{
	int x=0,f=1;
	char c=getchar();
	while(!isdigit(c))
	{
		if(c=='-')
			f=-1;
		c=getchar();
	}
	while(isdigit(c))
	{
		x=x*10+c-48;
		c=getchar();
	}
	return x*f;
}
ll lrd()
{
	ll x=0,f=1;
	char c=getchar();
	while(!isdigit(c))
	{
		if(c=='-')
			f=-1;
		c=getchar();
	}
	while(isdigit(c))
	{
		x=x*10+c-48;
		c=getchar();
	}
	return x*f;
}
const int N=1e6+10;
int n;
ll a[N];
ll tong[N];
ll sol1ans=0;
ll col[20];
ll cal()
{
	ll sum=0;
	for(int i=1;i<=n;i++)
		for(int j=i-1;j>=1;j--)
			if(col[i]==col[j])
			{
				if(a[i]==a[j])
					sum+=a[i];
				break;
			}
	return sum;
}
void dfs(int dep)
{
	if(dep>n)
	{
		sol1ans=max(sol1ans,cal());
		return;
	}
	col[dep]=1;
	dfs(dep+1);
	col[dep]=0;
	dfs(dep+1);
}
void sol1()
{
	sol1ans=0;
	for(int i=1;i<=n;i++)
		a[i]=lrd();
	memset(col,0,sizeof(col));
	dfs(1);
	cout<<sol1ans<<endl;
}
int main()
{
	freopen("color.in","r",stdin);
	freopen("color.out","w",stdout);
	int T=rd();
	while(T--)
	{
		memset(tong,0,sizeof(tong));
		n=rd();
		if(n<=15)
		{
			sol1();
			continue;
		}
		ll ans=0,maxa=0;
		for(int i=1;i<=n;i++)
		{
			a[i]=lrd();
			tong[a[i]]++;
			maxa=max(maxa,a[i]);
		}	
		for(ll i=1;i<=maxa;i++)
			if(tong[i])
				ans+=(tong[i]-1)*i;
		cout<<ans<<endl;
	}
	return 0;
}
